<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	
	$kboy_userid = $_SESSION['kboy_userid'];
	$kboy_user = $_SESSION['kboy_user'];

	$action = chkstr(trim($_REQUEST['action']));
	$photo_pic = chkstr(trim($_REQUEST['photo_pic']));
	$aid = chkstr(trim($_REQUEST['aid']));
	$picid = $_REQUEST['picid'];
	$photo_title = $_REQUEST['photo_title'];
	$photo_face = chkstr(trim($_REQUEST['photo_face']));
	
	if($action == "add"){
		if(empty($aid)){
			echo erro("参数错误");
		}
		if(!is_numeric($aid)){
			echo erro("参数错误");
		}
		if(getNewsNums("kboy_forum_album","uid=$kboy_userid and id=$aid") <1){
			echo erro("参数错误");
		}
		if(file_exists(ltrim($photo_pic,'/'))){
			// 添加数据
			$mysql = new sqlstr("kboy_forum_pic"); 
			$mysql -> set("photo_pic",$photo_pic);
			$mysql -> set("uid",$kboy_userid,true);
			$mysql -> set("aid",$aid,true);
			$news_sql = $mysql -> insertSql();
			$news_res = mysql_query($news_sql);
			if(!$news_res){
				echo erro("服务器内部错误");
			}
		}
	}elseif($action == "edit"){
		$id_count = count($picid); // 获取数组个数
		if(empty($id_count)){
			echo erro("参数错误");
		}
	
		mysql_query("update kboy_forum_pic set photo_face=0 where uid=$kboy_userid and aid=$aid");
		for($i=0; $i<$id_count; $i++){
			
			// 修改数据
			
			$mysql = new sqlstr("kboy_forum_pic"); 
			$mysql -> set("photo_title",$photo_title[$i]);
			if($photo_face == $picid[$i]){
			$mysql -> set("photo_face",1,true);
			}else{
			$mysql -> set("photo_face",0,true);
			}
			$mysql -> set("photo_isedit",1,true);
			$news_sql = $mysql -> updateSql("uid=$kboy_userid and id=".$picid[$i]);
			$news_res = mysql_query($news_sql);
			if(!$news_res){
				echo erro("服务器内部错误");
			}
		}
		echo ok("操作成功","forum_photo.php?uid=$kboy_userid");
	
	}else{
		echo erro("参数错误");
	}
?>
